package com.yilin.tms.system.controller;

import com.yilin.tms.core.application.PageData;
import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.commons.annotation.NotNull;
import com.yilin.tms.core.entity.system.handle.Complaint;
import com.yilin.tms.core.entity.system.handle.Feedback;
import com.yilin.tms.system.service.IHandleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/system/handle/")
public class HandleController extends BaseController {

    @Resource
    IHandleService handleService;

    /**
     * 获取投诉列表
     */
    @PostMapping("getComplaintPage")
    public ReturnData<Object> getComplaintPage(Complaint query, Integer page, Integer limit) {
        PageData<Complaint> map = handleService.getComplaintPage(query, page, limit);
        return jsonView(SUCCESS_CODE, "获取列表成功", map);
    }

    /**
     * 获取反馈列表
     */
    @PostMapping("getFeedbackPage")
    public ReturnData<Object> getFeedbackPage(Feedback query, Integer page, Integer limit) {
        PageData<Feedback> map = handleService.getFeedbackPage(query, page, limit);
        return jsonView(SUCCESS_CODE, "获取列表成功", map);
    }

    /**
     * 用户发起投诉
     */
    @PostMapping("saveComplaint")
    @NotNull({"title","complaintType","complaintSourceId","toOrganizeId"})
    public ReturnData<Object> saveComplaint(Complaint complaint) {
        complaint.setFromAccountId(getLoginUser().getId());
        complaint.setFromAccountName(getLoginUser().getName());
        complaint.setFromAccountPhone(getLoginUser().getPhone());
        handleService.saveComplaint(complaint);
        return jsonView(SUCCESS_CODE, "操作成功");
    }

    /**
     * 用户提交反馈
     */
    @PostMapping("saveFeedback")
    @NotNull({"title","context"})
    public ReturnData<Object> saveFeedback(Feedback feedback) {
        feedback.setAccountId(getLoginUser().getId());
        feedback.setAccountName(getLoginUser().getName());
        feedback.setAccountPhone(getLoginUser().getPhone());
        handleService.saveFeedback(feedback);
        return jsonView(SUCCESS_CODE, "操作成功");
    }

    /**
     * 处理 投诉
     */
    @PostMapping("dealComplaint")
    @NotNull({"id","complaintResult"})
    public ReturnData<Object> dealComplaint(Complaint complaint) {
        handleService.dealComplaint(complaint, getLoginUser());
        return jsonView(SUCCESS_CODE, "操作成功");
    }

    /**
     * 处理 反馈
     */
    @PostMapping("dealFeedback")
    @NotNull({"id"})
    public ReturnData<Object> dealFeedback(Feedback feedback) {
        handleService.dealFeedback(feedback, getLoginUser());
        return jsonView(SUCCESS_CODE, "操作成功");
    }
}
